<!--This file is the Logic part (Database part) for Upload.-->

<?php

include 'DBLibrary/config.php';
include 'DBLibrary/openDB.php';
mysql_select_db($dbname);

define('FileFolder', 'FilesUploaded/');

if (isset($_POST['upload'])) {
    $desc = $_POST['desc'];
    $dafile = $_FILES['uploadfile']['name'];
    $target = FileFolder . $dafile;

    if (($_FILES["uploadfile"]["type"] == "image/gif")
            || ($_FILES["uploadfile"]["type"] == "image/jpeg")
            || ($_FILES["uploadfile"]["type"] == "image/png" )
            || ($_FILES["uploadfile"]["type"] == "image/jpg" )
            || ($_FILES["uploadfile"]["type"] == "application/zip")
            || ($_FILES["uploadfile"]["type"] == "application/pdf" )
            || ($_FILES["uploadfile"]["type"] == "application/msword")
            || ($_FILES["uploadfile"]["type"] == "application/vnd.openxmlformats-officedocument.wordprocessingml.document")
            || ($_FILES["uploadfile"]["type"] == "application/vnd.ms-excel")
            || ($_FILES["uploadfile"]["type"] == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            || ($_FILES["uploadfile"]["type"] == "application/vnd.openxmlformats-officedocument.spreadsheetml.template")
            || ($_FILES["uploadfile"]["type"] == "application/vnd.ms-powerpoint" )
            || ($_FILES["uploadfile"]["type"] == "application/vnd.openxmlformats-officedocument.presentationml.presentation" )
            || ($_FILES["uploadfile"]["type"] == "application/vnd.openxmlformats-officedocument.presentationml.template" )
            || ($_FILES["uploadfile"]["type"] == "application/vnd.openxmlformats-officedocument.presentationml.slideshow" )
            || ($_FILES["uploadfile"]["type"] == "text/plain")
            || ($_FILES["uploadfile"]["type"] == "application/octet-stream" )) {
        if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $target)) {
            
            $confirm = mysql_query("INSERT INTO `rotaract`.`file` (`fileName`, `directory`, `desc`) VALUES ('$dafile', '$target', '$desc');");
        }
    }
}
include 'DBLibrary/closeDB.php';
?>
